
//Install packages if needed
ssc install estout
net install grc1leg2


//Set working directory first

use "Experiment data.dta", clear 

do "Experiment variable code.do"



/////////////////////////////////////////Figure 1 - combined policies and parties
eststo clear
eststo: reg likepolicy treatment##c.racialtherm 
eststo: reg likepolicy treatment##c.racialtherm age edu income man unemployed union i.partyID 

esttab using likepolicy.rtf , se r2 ar2  b(2) compress modelwidth(5) replace nobaselevels label ///
varlabels(1.treatment Treatment racialtherm RacialTherm 1.treatment#c.racialtherm "Treatment*RacialTherm"  age Age edu Education income Income man Man unemployed Unemployed union "Union Member" _cons Intercept) ///
title(Table 1B - Used in Figure 1) nonumbers mtitles("Bivariate" "Controls") 

margins, over(treatment ) at((mean)_all racialtherm=(0(.1)1))
marginsplot,   recast(line) recastci(rarea) noci legend(position(6)) xsize(5) ysize(5) name(LikePolicies, replace) scheme(plottig) 
graph display LikePolicies
margins, over(r.treatment ) at((mean)_all racialtherm=(0(.01)1))
marginsplot,   recast(line) recastci(rarea)   legend(on) legend(position(6)) xsize(6) ysize(5)   name(TreatmentLikePolicies, replace) scheme(plottig) ysc(titlegap(-7))

grc1leg2  LikePolicies TreatmentLikePolicies , row(1)  scheme(plottig) commonscheme  name(Figure1, replace) 
graph save "Figure 1 - Racial Spillover.gph", replace
graph use "Figure 1 - Racial Spillover.gph", play("experimentcombined.grec") 
graph save "Figure 1 - Racial Spillover.gph", replace
graph export "Figure 1 - Racial Spillover.pdf", as(pdf) replace


/////////////////////////////////////////Figure 2 - Partisans

// NDP
eststo clear
eststo: reg likepolicy treatment##c.racialtherm age edu income man unemployed union    if partyID==2
margins, over(r.treatment ) at((mean)_all racialtherm=(0(.1)1))
marginsplot,   recast(line) recastci(rarea)  scheme(plotplain) legend(position(6)) nodraw ysc(titlegap(-10)) xsize(6) ysize(5)
graph save Graph "NDP.gph", replace
  
//Liberals 
eststo: reg likepolicy treatment##c.racialtherm age edu income man unemployed union   if partyID==1
margins, over(r.treatment ) at((mean)_all racialtherm=(0(.1)1))
marginsplot,   recast(line) recastci(rarea)  scheme(plotplain) legend(position(6)) nodraw ysc(titlegap(-10)) xsize(6) ysize(5)
graph save Graph "Liberals.gph", replace

//Conservatives
eststo: reg likepolicy treatment##c.racialtherm age edu income man unemployed union   if partyID==0
margins, over(r.treatment ) at((mean)_all racialtherm=(0(.1)1))
marginsplot,   recast(line) recastci(rarea)  scheme(plotplain) legend(position(6)) nodraw ysc(titlegap(-10)) xsize(6) ysize(5)
graph save Graph "Conservatives.gph", replace

//NonPartisans
eststo: reg likepolicy treatment##c.racialtherm age edu income man unemployed union  if partyID==5
margins, over(r.treatment ) at((mean)_all racialtherm=(0(.1)1))
marginsplot,   recast(line) recastci(rarea)  scheme(plotplain) legend(position(6)) nodraw ysc(titlegap(-10)) xsize(6) ysize(5)
graph save Graph "NonPartisans.gph", replace

gr combine "NDP.gph"  "Liberals.gph" "Conservatives.gph" "NonPartisans.gph", ycommon  scheme(plottig) commonscheme play("partisan colours")  xsize(6) ysize(5)
graph save Graph "Figure 2 - Partisans.gph", replace
graph export "Figure 2 - Partisans.pdf", replace

esttab using likepolicybyparty.rtf , se r2 ar2  b(2) compress modelwidth(5) replace nobaselevels label ///
varlabels(1.treatment Treatment racialtherm RacialTherm 1.treatment#c.racialtherm "Treatment*RacialTherm"  age Age edu Education income Income man Man unemployed Unemployed union "Union Member" _cons Intercept) ///
title("Table 2B - Racial Spillover by Party Identification (used in Figure 2)") nonumbers mtitles("NDP" "Liberals" "Conservatives" "Non-Partisans") 


//////////Compare slopes of parties, discussed in text
eststo clear
eststo NDP:  reg likepolicy treatment##c.racialtherm age edu income man unemployed union    if partyID==2
eststo LIB: reg likepolicy treatment##c.racialtherm age edu income man unemployed union   if partyID==1
eststo CON: reg likepolicy treatment##c.racialtherm age edu income man unemployed union   if partyID==0
eststo NONE: reg likepolicy treatment##c.racialtherm age edu income man unemployed union  if partyID==5

suest   NDP LIB CON NONE

test [NDP_mean ]1.treatment#c.racialtherm =[LIB_mean ]1.treatment#c.racialtherm 
test [NDP_mean ]1.treatment#c.racialtherm =[CON_mean ]1.treatment#c.racialtherm 
test [NDP_mean ]1.treatment#c.racialtherm =[NONE_mean ]1.treatment#c.racialtherm




///////////////////////////////////////// Figure 3 - Policies
eststo clear
eststo: reg plastic treatment##c.racialtherm age edu income man unemployed union i.partyID
margins, over(treatment ) at((mean)_all racialtherm=(0(.2)1))
marginsplot,   recast(line) recastci(rarea) 
margins, over(r.treatment ) at((mean)_all racialtherm=(0(.2)1))
marginsplot,   recast(line) recastci(rarea)  scheme(plotplain) legend(position(6))
graph save Graph "BanPlastic.gph", replace

eststo: reg moreie treatment##c.racialtherm age edu income man unemployed union i.partyID
margins, over(treatment ) at((mean)_all racialtherm=(0(.2)1))
marginsplot,   recast(line) recastci(rarea) 
margins, over(r.treatment ) at((mean)_all racialtherm=(0(.2)1))
marginsplot,   recast(line) recastci(rarea)  scheme(plotplain) legend(position(6))
graph save Graph "MoreEI.gph", replace

eststo: reg pharm treatment##c.racialtherm age edu income man unemployed union i.partyID
margins, over(treatment ) at((mean)_all racialtherm=(0(.2)1))
marginsplot,   recast(line) recastci(rarea) 
margins, over(r.treatment ) at((mean)_all racialtherm=(0(.2)1))
marginsplot,   recast(line) recastci(rarea)  scheme(plotplain) legend(position(6))
graph save Graph "PharmaCare.gph", replace

eststo: reg onlinediscrim treatment##c.racialtherm age edu income man unemployed union i.partyID
margins, over(treatment ) at((mean)_all racialtherm=(0(.2)1))
marginsplot,   recast(line) recastci(rarea) 
margins, over(r.treatment ) at((mean)_all racialtherm=(0(.2)1))
marginsplot,   recast(line) recastci(rarea)  scheme(plotplain) legend(position(6))
graph save Graph "OnlineDiscm.gph", replace

eststo: reg indiglang treatment##c.racialtherm age edu income man unemployed union i.partyID
margins, over(treatment ) at((mean)_all racialtherm=(0(.2)1))
marginsplot,   recast(line) recastci(rarea) 
margins, over(r.treatment ) at((mean)_all racialtherm=(0(.2)1))
marginsplot,   recast(line) recastci(rarea)  scheme(plotplain) legend(position(6))
graph save Graph "IndigLang.gph", replace

gr combine "BanPlastic.gph" "MoreEI.gph"  "PharmaCare.gph"  "OnlineDiscm.gph" "IndigLang", ycommon  scheme(plottig) commonscheme play("policy colours")
graph save Graph "Figure 3 - Policies.gph", replace
graph export "Figure 3 - Policies.pdf", replace


esttab using likepolicybyparty.rtf , se r2 ar2  b(2) compress modelwidth(5) replace nobaselevels label ///
varlabels(1.treatment Treatment racialtherm RacialTherm 1.treatment#c.racialtherm "Treatment*RacialTherm"  age Age edu Education income Income man Man unemployed Unemployed union "Union Member" _cons Intercept) ///
title("Table 3B - Specific Policy Models (Figure 3)") nonumbers mtitles("Ban Plastic" "Employment Insurance" "PharmaCare" "Online Racism" "Indigenous Languages") 



//////////Compare slopes of policies, discussed in text
eststo clear
eststo plastic: reg plastic treatment##c.racialtherm age edu income man unemployed union i.partyID
eststo moreie: reg moreie treatment##c.racialtherm age edu income man unemployed union i.partyID
eststo pharm: reg pharm treatment##c.racialtherm age edu income man unemployed union i.partyID
eststo onlinediscrim: reg onlinediscrim treatment##c.racialtherm age edu income man unemployed union i.partyID
eststo indiglang: reg indiglang treatment##c.racialtherm age edu income man unemployed union i.partyID

suest   plastic moreie pharm onlinediscrim indiglang

test [plastic_mean ]1.treatment#c.racialtherm =[moreie_mean ]1.treatment#c.racialtherm 
test [plastic_mean ]1.treatment#c.racialtherm =[pharm_mean ]1.treatment#c.racialtherm 
test [plastic_mean ]1.treatment#c.racialtherm =[onlinediscrim_mean ]1.treatment#c.racialtherm
test [plastic_mean ]1.treatment#c.racialtherm =[indiglang_mean ]1.treatment#c.racialtherm









/////////////////////////// ////////////////////////////////////////////////////////Appendix

///////////////////////////////////////// Figure 1A - Controlling for Leader Thermometer


eststo clear
eststo: reg likepolicy treatment##c.racialtherm treatment##c.singhtherm 
eststo: reg likepolicy treatment##c.racialtherm treatment##c.singhtherm age edu income man unemployed union i.partyID

esttab using "Table 1A - Controlling  for Leader Thermometer.rtf", se r2 ar2  b(2) compress modelwidth(5) replace nobaselevels label ///
varlabels(1.treatment Treatment racialtherm RacialTherm 1.treatment#c.racialtherm "Treatment*RacialTherm"  singhtherm SinghTherm 1.treatment#c.singhtherm "Treatment*SinghTherm" ///
age Age edu Education income Income man Man unemployed Unemployed union "Union Member" _cons Intercept) ///
title(Table 1A - Controling for Leader Thermometer) nonumbers mtitles("No Controls" "Controls") 
 
margins, over(treatment ) at((mean)_all racialtherm=(0(.1)1))
marginsplot, nodraw  recast(line) recastci(rarea) noci legend(position(6)) xsize(5) ysize(5) name(LikePolicies, replace) scheme(plottig) 
graph display LikePolicies
margins, over(r.treatment ) at((mean)_all racialtherm=(0(.01)1))
marginsplot, nodraw  recast(line) recastci(rarea)   legend(on) legend(position(6)) xsize(6) ysize(5)   name(TreatmentLikePolicies, replace) scheme(plottig) ysc(titlegap(-7))

grc1leg2  LikePolicies TreatmentLikePolicies , row(1)  scheme(plottig) commonscheme  name(Figure1A, replace) 
graph save "Figure 1A - Leader Thermometer.gph", replace
graph use "Figure 1A - Leader Thermometer.gph", play("experimentcombined.grec") 
graph save "Figure 1A - Leader Thermometer.gph", replace


 
/////////////////////////////////////////Figure 2A -  Immigrant Thermometer 
eststo clear
eststo: reg likepolicy treatment##c.immtherm 
eststo: reg likepolicy treatment##c.immtherm age edu income man unemployed union i.partyID 

esttab using "Table 2A - Immigrant Thermometer.rtf" , se r2 ar2  b(2) compress modelwidth(5) replace nobaselevels label ///
varlabels(1.treatment Treatment immtherm ImmigrantTherm 1.treatment#c.immtherm "Treatment*ImmigrantTherm"  age Age edu Education income Income man Man unemployed Unemployed union "Union Member" _cons Intercept) ///
title(Table 1B - Immigrant Thermometer) nonumbers mtitles("Bivariate" "Controls") 

margins, over(treatment ) at((mean)_all immtherm=(0(.1)1))
marginsplot, nodraw  recast(line) recastci(rarea) noci legend(position(6)) xsize(5) ysize(5) name(LikePolicies, replace) scheme(plottig) 
graph display LikePolicies
margins, over(r.treatment ) at((mean)_all immtherm=(0(.01)1))
marginsplot, nodraw  recast(line) recastci(rarea)   legend(on) legend(position(6)) xsize(6) ysize(5)   name(TreatmentLikePolicies, replace) scheme(plottig) ysc(titlegap(-7))

grc1leg2  LikePolicies TreatmentLikePolicies , row(1)  scheme(plottig) commonscheme  name(Figure2A, replace) 
graph save "Figure 2A - Imm Thermometer.gph", replace
graph use "Figure 2A - Imm Thermometer.gph", play("experimentcombined.grec") 
graph save "Figure 2A - Imm Thermometer.gph", replace



///////////////////////////////////////// Figure 5A - Interaction with Interest
eststo clear
eststo: reg likepolicy treatment##c.racialtherm##c.interest 
eststo: reg likepolicy treatment##c.racialtherm##c.interest age edu income man unemployed union i.partyID 
esttab using likepolicyinterest.rtf , se r2 ar2  b(2) compress modelwidth(5) replace nobaselevels label ///
varlabels( 1.treatment#c.racialtherm#c.interest "Interest*RacialTherm*Treatment" c.racialtherm#c.interest "Interest*RacialTherm" 1.treatment#c.interest "Interest*Treatment" interest Interest 1.treatment Treatment racialtherm RacialTherm 1.treatment#c.racialtherm "Treatment*RacialTherm"  age Age edu Education income Income man Man unemployed Unemployed union "Union Member"  _cons Intercept) ///
title(Table 8A - Interaction with Interest) nonumbers mtitles("Bivariate" "Controls") 

margins, over(r.treatment ) at((mean)_all racialtherm=(0(.1)1) interest=(.5 .8 ))
marginsplot,   recast(line) recastci(rarea)  scheme(plottig) legend(position(6)) xsize(6) ysize(5) play("treatment plot") 
graph save Graph "Figure 5A - Political Interest.gph", replace 



///////////////////////////////////////// Figure 6A - Interaction with Media
eststo clear
eststo: reg likepolicy treatment##c.racialtherm##c.media 
eststo: reg likepolicy treatment##c.racialtherm##c.media age edu income man unemployed union i.partyID 
esttab using likepolicynews.rtf , se r2 ar2  b(2) compress modelwidth(5) replace nobaselevels label ///
varlabels( 1.treatment#c.racialtherm#c.media "Interest*RacialTherm*News" c.racialtherm#c.media "News*RacialTherm" 1.treatment#c.media "News*Treatment" interest Interest 1.treatment Treatment racialtherm RacialTherm 1.treatment#c.racialtherm "Treatment*RacialTherm"  age Age edu Education income Income man Man unemployed Unemployed union "Union Member"  _cons Intercept) ///
title(Table 9A - Interaction with News Consumption) nonumbers mtitles("Bivariate" "Controls") 

margins, over(r.treatment ) at((mean)_all racialtherm=(0(.1)1) media=(.2 .8 ))
marginsplot,   recast(line) recastci(rarea)  scheme(plottig) legend(position(6)) xsize(6) ysize(5) play("treatment plot") 
graph save Graph "Figure 6A - News Consumption.gph", replace 
graph export "Figure 6A - News Consumption.pdf", replace



///////////////////////////////////////// Table 3A - Alternative attitudes
eststo clear
eststo: reg likepolicy treatment##c.diffnonwhite age edu income man unemployed union i.partyID 
eststo: reg likepolicy treatment##c.canvalues age edu income man unemployed union i.partyID 
eststo: reg likepolicy treatment##c.immcost age edu income man unemployed union i.partyID 
eststo: reg likepolicy treatment##c.minorityexempt age edu income man unemployed union i.partyID 
eststo: reg likepolicy treatment##c.realref age edu income man unemployed union i.partyID 

esttab using altracialmeasures.rtf , se r2 ar2  b(2) compress modelwidth(5) replace nobaselevels label ///
varlabels(1.treatment Treatment diffnonwhite DiffNonWhite 1.treatment#c.diffnonwhite "Treatment*DiffNonWhite" ///
canvalues AdoptValues 1.treatment#c.canvalues "Treatment*AdoptValues" ///
immcost ImmCost 1.treatment#c.immcost "Treatment*ImmCost" ///
minorityexempt MinorityExempt 1.treatment#c.minorityexempt "Treatment*MinorityExempt" ///
realref RealRefugees 1.treatment#c.realref "Treatment*RealRefugees" ///
age Age edu Education income Income man Man unemployed Unemployed union "Union Member" _cons Intercept) ///
title(Table 3A - Alternative Measures of Racial Attitudes) nonumbers mtitles("Harder for Non-Whites" "Adopt Values" "Immigrant Costs" "Minority Exempt" "Real Refugees") 
